package com.buddy.qreport.datasource.dynamic;

import java.util.UUID;

/**
 * 数据源id上下文持有者
 * 后续还需要对同步操作进行优化
 */
public class DataSourceContextHolder {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static final String DEFAULT_DATASOURCE_ID = UUID.randomUUID().toString();

    public static  void setDataSourceId(String id){

        contextHolder.set(id);
    }

    public static  String getDataSourceId(){

        String id =  contextHolder.get();

        if(id == null){

            return DEFAULT_DATASOURCE_ID;
        }

        return id;
    }


    public static  void clearId(){

        contextHolder.remove();
    }

}
